var API_URL='https://m3.xiaoyu.com/welcome/wechatapp';

Page({
  data: {
    active:0,
    errCode:0,
    wpierimg:[],
    special:[],
    paged:1,
    loading: false
  },
  onLoad: function () {
    var _this =this;
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 10000
    });

    wx.request({
      url:API_URL,
      data:{
        callback:"home.index",
        page:1
      },
      header: {
          'content-type': 'application/json'
      },
      success: function(res) {
        wx.hideToast();
        var data = res.data;
        _this.setData({
          errCode:data.errCode,
          wpierimg:data.data.banner,
          special:data.data.list
        });
      }
    })
  },
  swiperChange:function(e){
  var index = e.detail.current;
    this.setData({
      active:index
    });
  },
  onReachBottom: function(){

    var paged = this.data.paged + 1;
    var _this =this;
    _this.setData({
      loading: true
    });

    wx.request({
      url:API_URL,
      data:{
        callback:"home.index",
        page:paged
      },
      header: {
          'content-type': 'application/json'
      },
      success: function(res) {
        var data = res.data;
        _this.setData({
          paged: paged,
          special:_this.data.special.concat(data.data.list),
          loading: false
        });
      }
    })
  },

  onPullDownRefresh: function () {
    var _this =this;
    wx.request({
      url:API_URL,
      data:{
        callback:"home.index",
        page:1
      },
      header: {
          'content-type': 'application/json'
      },
      success: function(res) {
        var data = res.data;
        wx.stopPullDownRefresh;
        _this.setData({
          errCode:data.errCode,
          wpierimg:data.data.banner,
          special:data.data.list
        });
        wx.stopPullDownRefresh(); //停止下拉刷新
      }
    })
  },

  onShareAppMessage: function () {
    return {
      title: '小鱼网',
      desc: '',
      path: 'pages/index/index'
    }
  }

})